package com.topc.problem.api;

import cn.hutool.core.util.ObjectUtil;
import com.topc.base.api.CommonResult;
import com.topc.base.model.PageParams;
import com.topc.base.model.PageResult;
import com.topc.base.model.UserAuthDto;
import com.topc.base.utils.PageUtils;
import com.topc.problem.model.dto.QueryComposeInfoDto;
import com.topc.problem.model.dto.QueryProblemInfoDto;
import com.topc.problem.model.dto.QueryTagDto;
import com.topc.problem.model.dto.SaveProblemComposeDto;
import com.topc.problem.model.po.ProblemComposeInfo;
import com.topc.problem.model.po.ProblemInfo;
import com.topc.problem.model.po.ProblemTag;
import com.topc.problem.model.vo.ComposeShowVo;
import com.topc.problem.model.vo.ParentTagVo;
import com.topc.problem.model.vo.ProblemPageShowVo;
import com.topc.problem.model.vo.TagTreeShowVo;
import com.topc.problem.service.IProblemComposeInfoService;
import com.topc.problem.service.IProblemInfoService;
import com.topc.problem.service.IProblemTagService;
import com.topc.problem.util.SecurityUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.bind.DefaultValue;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@RequestMapping("/open")
public class ProblemOpenController {

    @Autowired
    private IProblemTagService problemTagService;

    @Autowired
    private IProblemInfoService problemInfoService;

    @Autowired
    private IProblemComposeInfoService problemComposeInfoService;

    @GetMapping("/parent-tag")
    public CommonResult<List<ParentTagVo>> getParentTagList() {
        List<ParentTagVo> list = problemTagService.getParentTagList();
        return CommonResult.success(list);
    }

    @GetMapping("/tree-tag")
    public CommonResult<List<TagTreeShowVo>> getTagTreeShowVo() {
        List<TagTreeShowVo> tagTreeShowVos = problemTagService.getTagTreeShowVo();
        return CommonResult.success(tagTreeShowVos);
    }

    @PostMapping("/search-tag")
    public CommonResult<PageResult<ProblemTag>> searchTagByPage(PageParams pageParams, @RequestBody @Validated QueryTagDto queryTagDto) {
        if (ObjectUtil.isNotEmpty(queryTagDto.getId()))
            return CommonResult.success(PageUtils.idPageResult(problemTagService.getById(queryTagDto.getId())));
        PageResult<ProblemTag> problemTagPageResult = problemTagService.searchByPage(pageParams, queryTagDto);
        return CommonResult.success(problemTagPageResult);
    }

    @PostMapping("/search-compose")
    public CommonResult<PageResult<ProblemComposeInfo>> searchComposeByPage(PageParams pageParams,String title) {
        QueryComposeInfoDto queryComposeInfoDto = new QueryComposeInfoDto();
        queryComposeInfoDto.setStatus(-1);
        queryComposeInfoDto.setIsPrivate(-1);
        queryComposeInfoDto.setTitle(title);
        PageResult<ProblemComposeInfo> problemComposeInfoPageResult = problemComposeInfoService.searchByPage(pageParams, queryComposeInfoDto,0);
        return CommonResult.success(problemComposeInfoPageResult);
    }


}
